//
// Created by tanke on 23-11-29.
//

#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int cmpFunc(const void* ptr1, const void* ptr2)
{
    int val1 = *((int*)ptr1);
    int val2 = *((int*)ptr2);

    return val1 - val2;
}

long long numberOfWeeks(int* milestones, int milestonesSize)
{
    long long result = 0;
    long long sum = 0;

    qsort(milestones, milestonesSize, sizeof(int), cmpFunc);

    for (int i = 0; i < milestonesSize; i ++) {
        sum += milestones[i];
    }

    if (milestones[milestonesSize-1] <= sum / 2) {
        result = sum;
        return result;
    }

    result = (sum - milestones[milestonesSize-1]) * 2 + 1;
    return result;
}

int main(void)
{
    int nums[3] = {1, 2, 3};
    printf("%lld\n", numberOfWeeks(nums, 3));

    int nums1[3] = {5, 2, 1};
    printf("%lld\n", numberOfWeeks(nums1, 3));

    int nums2[6] = {9, 3, 6, 8, 2, 1};
    printf("%lld\n", numberOfWeeks(nums2, 6));

    int nums3[1] = {1};
    printf("%lld\n", numberOfWeeks(nums3, 1));

    int nums4[6] = {5, 7, 5, 7, 9, 7};
    printf("%lld\n", numberOfWeeks(nums4, 6));
    return 0;
}